import java.util.Arrays;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution55 {

    public static void main(String args[]) {
        Solution55 s = new Solution55();
        System.out.println(s.canJump(new int[]{2, 2, 2, 0, 4}));
    }

    public boolean canJump(int[] nums) {
        int n = nums.length;
        if (n <= 1) {
            return true;
        }
        int[] dp = new int[n];
        for (int i = 0; i < nums.length; i++) {
            dp[i] = i + nums[i];
        }
        int maxv = dp[0];
        for (int i = 1; maxv >= i && i < n; i++) {
            maxv = Math.max(maxv, dp[i]);
        }
        return maxv >= n - 1 ? true : false;
    }

}
